from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database
from utils.noticeUtils.dingtalkControl import DingTalkSendMsg


class TestMonitorReplenishmentQueue:
    """
    监控temu自动补货及时性
    """
    zhcxkj_center_strategy_comprehensive_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "HWY-ZH-GZ-RDS-strategy")



    def test_monitor_replenishment_queue(self):
        source_id_List = [22091,22743,22913,23185,23256,23257,23284,23255]
        get_create_name = f"""
        SELECT create_time 
        FROM zhcxkj_center_strategy_comprehensive.`t_temu_replenishment_queue` 
        WHERE source_id = %s 
        order BY id DESC LIMIT 1
        """
        text = ""
        for source_id in source_id_List:
            # t_temu_ordersource_authorization
            create_name = self.zhcxkj_center_strategy_comprehensive_db.fetch_all_tuple(get_create_name,(source_id,))
            if not len(create_name):
                text += f"渠道={source_id}<font color='red' size='5'><b>未查询到补货信息</b></font>\n\n\n"
                continue
            text += f"渠道={source_id}补货队列最新创建时间=<font color='red' size='5'><b>{create_name[0][0]}</b></font>\n\n\n"

        DingTalkSendMsg(DingTalk='temu_monitor').send_success(text=text,
                                                                      title='Temu自动补货执行监控',
                                                                      phone_list=[18118758151, 18576757471,18827206463])

        print("Temu自动补货执行监控监控任务执行完成")  # DingTalk_auto all_platform_monitor

if __name__ == '__main__':
    TestMonitorReplenishmentQueue().test_monitor_replenishment_queue()


